package teste.servico.ejb;

import java.sql.Connection;

import javax.ejb.Local;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.naming.InitialContext;
import javax.sql.DataSource;

import org.hibernate.Session;

import projeto.entidade.OperacaoFinanceira;
import teste.servico.Projeto002Servico;
import teste.servico.Projeto002ServicoLocal;
import teste.servico.Projeto002ServicoRemote;


@Stateless
@Local(Projeto002ServicoLocal.class)
@Remote(Projeto002ServicoRemote.class)
public class Projeto002ServicoEJB extends ParentProjetoServicoEJB implements Projeto002Servico {

	public void recuperarOperacaoFinanceira() {
		System.out.println("recuperarOperacaoFinanceira() - start");
		Session s = (Session) getEm().getDelegate();
		OperacaoFinanceira object = (OperacaoFinanceira) s.createCriteria(OperacaoFinanceira.class).list().get(0);
		System.out.println(object);
		System.out.println(object.getDescricao());
		System.out.println("em:" + getEm());
		System.out.println("lookup:" + lookup());
		System.out.println("ProjetoServico002 fazendo algo remotamente");
		System.out.println("recuperarOperacaoFinanceira() - end");
	}

	private Connection lookup() {
		Connection conn = null;
		try{
			InitialContext ic = new InitialContext();
			 DataSource ds = (DataSource) ic.lookup("java:jdbc/ProjetoDS");
			conn =   ds.getConnection();			
		}catch(Exception e){
			e.printStackTrace();
		}
		return conn ;
	}
	


}
